home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mint99s / mem.h < prev    next >
C/C++ Source or Header  |  1992-12-23  |  6KB  |  198 lines

  1. /*
  2. Copyright 1990,1991,1992 Eric R. Smith.
  3. Copyright 1992 Atari Corporation.
  4. All rights reserved.
  5. */
  6.  
  7. #ifndef _mem_h
  8. #define _mem_h
  9.  
  10. #include "file.h"
  11.  
  12. typedef struct memregion {
  13.     long    loc;        /* base of memory region */
  14.     ulong    len;        /* length of memory region */
  15.     ushort    links;        /* number of users of region */
  16.     ushort    mflags;        /* e.g. which map this came from */
  17.     struct memregion *next; /* next region in memory map */
  18. } MEMREGION;
  19.  
  20. /* dummy type for virtual addresses */
  21. typedef struct vaddr {
  22.     char dummy;
  23. } *virtaddr;
  24.  
  25. /*
  26.  * Here's the deal with memory bits:
  27.  *
  28.  * Mxalloc(long size, int mode) takes these fields in 'mode': BITS 0-2 hold
  29.  * values 0-3 for the old GEMDOS mode argument.  If bit 3 is on, then only
  30.  * F_PROTMODE (bits 4-7) counts, and it encodes the desired protection mode
  31.  * to change a block to. Else F_PROTMODE is the desired protection mode for
  32.  * the new block you're allocating.  In either case, F_PROTMODE turns into
  33.  * a PROT_* thusly: if it's zero, you get the F_PROTMODE value from curproc's
  34.  * prgflags. Else you get (F_PROTMODE >> F_PROTSHIFT)-1.
  35.  *
  36.  * The 0x4000 bit is carried along into get_region (but not from there into
  37.  * mark_region) and, if set, causes M_KEEP to be set in the region's
  38.  * mflags.
  39.  */
  40.  
  41. /* flags for memory regions */
  42. #define M_CORE        0x01    /* region came from core map */
  43. #define M_ALT        0x02    /* region came from alt map */
  44. #define M_SWAP        0x04    /* region came from swap map */
  45. #define M_KER        0x08    /* region came from kernel map */
  46. #define M_MAP        0x0f    /* and with this to pick out map */
  47.  
  48. #define M_SHTEXT    0x10    /* region is a shared text region */
  49. #define M_KEEP        0x0100    /* don't free on process termination */
  50.  
  51. /* structure for shared text regions */
  52.  
  53. typedef struct shtextreg {
  54.     FILEPTR *f;        /* what file did this come from? */
  55.     MEMREGION *text;    /* pointer to shared text region */
  56.     short mtime, mdate;    /* date & time for file */
  57.     struct shtextreg *next;
  58. } SHTEXT;
  59.  
  60. /* structure of exectuable program headers */
  61. typedef struct fileheader {
  62.     short    fmagic;
  63.     long    ftext;
  64.     long    fdata;
  65.     long    fbss;
  66.     long    fsym;
  67.     long    reserved;
  68.     long    flag;
  69.     short    reloc;
  70. } FILEHEAD;
  71.  
  72. #define GEMDOS_MAGIC 0x601a
  73.  
  74. /* flags for curproc->memflags */
  75. /* also used for program headers PRGFLAGS */
  76. #define F_FASTLOAD    0x01        /* don't zero heap */
  77. #define F_ALTLOAD    0x02        /* OK to load in alternate ram */
  78. #define F_ALTALLOC    0x04        /* OK to malloc from alt. ram */
  79. #define F_RESERVED    0x08        /* reserved for future use */
  80. #define F_MEMFLAGS    0xf0        /* reserved for future use */
  81. #define F_SHTEXT    0x800        /* program's text may be shared */
  82.  
  83. #define F_MINALT    0xf0000000L    /* used to decide which type of RAM to load in */
  84.  
  85. /* Bit in Mxalloc's arg for "don't auto-free this memory" */
  86. #define F_KEEP        0x4000
  87.  
  88. #define F_OS_SPECIAL    0x8000        /* mark as a special process */
  89.  
  90. /* flags for curproc->memflags (that is, PRGFLAGS) and also Mxalloc mode.  */
  91. /* (Actually, when users call Mxalloc, they add 0x10 to what you see here) */
  92. #define    F_PROTMODE    0xf0        /* protection mode bits */
  93. #define F_PROT_P    0x00        /* no read or write */
  94. #define F_PROT_G    0x10        /* any access OK */
  95. #define F_PROT_S    0x20        /* any super access OK */
  96. #define F_PROT_PR    0x30        /* any read OK, no write */
  97. #define F_PROT_I    0x40        /* invalid page */
  98.  
  99. /* actual values found in page_mode_table and used as args to alloc_region */
  100. #define PROT_P    0
  101. #define PROT_G    1
  102. #define PROT_S    2
  103. #define PROT_PR    3
  104. #define PROT_I    4
  105. #define PROT_PROTMODE 0xf   /* these bits are the prot mode */
  106. #define PROT_NOCHANGE -1
  107.  
  108. #define F_PROTSHIFT    4
  109.  
  110. typedef MEMREGION **MMAP;
  111.  
  112. #ifndef GENMAGIC
  113. extern MMAP core, alt, ker, swap;
  114. #endif
  115.  
  116. /* compilers differ on what "sizeof" returns */
  117. #define SIZEOF        (long)sizeof
  118.  
  119. /* QUANTUM: the page size for the mmu: 8K.  This is hard-coded elsewhere. */
  120. #define QUANTUM 0x2000L
  121.  
  122. /* MiNT leaves this much memory for TOS to use (8K)
  123.  */
  124. #define TOS_MEM        (QUANTUM)
  125.  
  126. /* MiNT tries to keep this much memory available for the kernel and other
  127.  * programs when a program is launched (8K)
  128.  */
  129. #define KEEP_MEM    (QUANTUM)
  130.  
  131. /*
  132.  * how much memory should be allocated to the kernel? (24K)
  133.  */
  134. #define KERNEL_MEM    (3*QUANTUM)
  135.  
  136. /* macro for rounding off region sizes to QUANTUM (page) boundaries */
  137. #define MASKBITS    (QUANTUM-1)
  138. #define ROUND(size) ((size + MASKBITS) & ~MASKBITS)
  139.  
  140. /* interesting memory constants */
  141.  
  142. #define EIGHT_K (0x400L*8L)
  143. #define ONE_MEG 0x00100000L
  144. #define LOG2_ONE_MEG 20
  145. #define LOG2_16_MEG 24
  146. #define LOG2_EIGHT_K 13
  147. #define SIXTEEN_MEG (0x400L*0x400L*16L)
  148.  
  149. /* macro for turning a curproc->base_table pointer into a 16-byte boundary */
  150. #define ROUND16(ld) ((long_desc *)(((ulong)(ld) + 15) & ~15))
  151.  
  152. /* TBL_SIZE is the size in entries of the A, B, and C level tables */
  153. #define TBL_SIZE (16)
  154. #define TBL_SIZE_BYTES (TBL_SIZE * sizeof(long_desc))
  155.  
  156. typedef struct {
  157.     short limit;
  158.     ushort zeros:14;
  159.     ushort dt:2;
  160.     struct long_desc *tbl_address;
  161. } crp_reg;
  162.  
  163. /* format of long descriptors, both page descriptors and table descriptors */
  164.  
  165. typedef struct {
  166.     ushort limit;        /* set to $7fff to disable */
  167.     ushort unused1:6;
  168.     ushort unused2:1;
  169.     ushort s:1;        /* 1 grants supervisor access only */
  170.     ushort unused3:1;
  171.     ushort ci:1;        /* cache inhibit: used in page desc only */
  172.     ushort unused4:1;
  173.     ushort m:1;        /* modified: used in page desc only */
  174.     ushort u:1;        /* accessed */
  175.     ushort wp:1;        /* write-protected */
  176.     ushort dt:2;        /* type */
  177. } page_type;
  178.  
  179. typedef struct long_desc {
  180.     page_type page_type;
  181.     struct long_desc *tbl_address;
  182. } long_desc;
  183.  
  184. typedef struct {
  185.     ushort enable:1;
  186.     ushort zeros:5;
  187.     ushort sre:1;
  188.     ushort fcl:1;
  189.     ushort ps:4;
  190.     ushort is:4;
  191.     ushort tia:4;
  192.     ushort tib:4;
  193.     ushort tic:4;
  194.     ushort tid:4;
  195. } tc_reg;
  196.  
  197. #endif /* _mem_h */
  198.